﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;
using System.Diagnostics;
using System.Windows.Media.Imaging;
using PhoneInfo.Converters;

namespace PhoneInfo
{
    public class Theme : DependencyObject
    {
        static Theme()
        {
            ImageBrush imageBlack = new ImageBrush();
            imageBlack.ImageSource = new BitmapImage(new Uri("/Icon/block/back_green.jpg", UriKind.Relative));
            imageBlack.Stretch = Stretch.Fill;
            //image.ImageSource=new Uri("");
            DefauletTheme.TextBrush = imageBlack;
            //Foreground="#31b2e7" 夜间模式
            DefauletTheme.TitleBrush = new SolidColorBrush(Common.HtmlToColor("#959595"));
            DefauletTheme.SecondTextBrush = new SolidColorBrush(Common.HtmlToColor("#626262"));
            DefauletTheme.BlueAndBlack = new SolidColorBrush(Common.HtmlToColor("#5c83a8"));
            DefauletTheme.GrayAndWhite = new SolidColorBrush(Common.HtmlToColor("#959595"));
            DefauletTheme.GrayAndBlue = new SolidColorBrush(Common.HtmlToColor("#535353"));
            DefauletTheme.NavyAndBlue = new SolidColorBrush(Common.HtmlToColor("#172d48"));
            DefauletTheme.IndexgrayAndWhite = new SolidColorBrush(Common.HtmlToColor("#626262"));
            DefauletTheme.lexunTBBackBrush = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
            DefauletTheme.lexunTBForgetBrush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
            DefauletTheme.ApplicationBarForgetBrush = new SolidColorBrush(Color.FromArgb(255, 0x31,0xb2, 0xe7));
            DefauletTheme.lexunReplyBackBrush = new SolidColorBrush(Color.FromArgb(255,0x32,0x32,0x32));
            //lexunReplyBackBrush  亮色模式
            ImageBrush imageGreen = new ImageBrush();
            imageGreen.Stretch = Stretch.Fill;
            imageGreen.ImageSource = new BitmapImage(new Uri("/Icon/back_green.jpg", UriKind.Relative));
            GreenTheme.TextBrush = imageGreen;
            GreenTheme.GrayAndWhite = new SolidColorBrush(Common.HtmlToColor("#ffffff"));
            GreenTheme.TitleBrush = new SolidColorBrush(Common.HtmlToColor("#025fae"));
            GreenTheme.SecondTextBrush = new SolidColorBrush(Common.HtmlToColor("#000000"));
            GreenTheme.BlueAndBlack = new SolidColorBrush(Common.HtmlToColor("#000000"));
            GreenTheme.GrayAndBlue = new SolidColorBrush(Common.HtmlToColor("#5c83a8"));
            GreenTheme.NavyAndBlue = new SolidColorBrush(Common.HtmlToColor("#599df1"));
            GreenTheme.IndexgrayAndWhite = new SolidColorBrush(Common.HtmlToColor("#ffffff"));
            GreenTheme.lexunTBBackBrush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
            GreenTheme.lexunTBForgetBrush = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
            GreenTheme.ApplicationBarForgetBrush = new SolidColorBrush(Color.FromArgb(255, 0x21, 0x21, 0x21));
            GreenTheme.lexunReplyBackBrush = new SolidColorBrush(Color.FromArgb(255, 0xcb, 0xe4, 0xf0));
            //默认使用Red主题

            TurnDefaulet();
        }

        public static void TurnDefaulet()
        {
            CurrentTheme.copy(DefauletTheme);
            isCurrentRed = true;
        }
        public static void TurnGreen()
        {
            CurrentTheme.copy(GreenTheme);
            isCurrentRed = false;
        }
        private static bool isCurrentRed = false;
        public static bool IsCurrentRed
        {
            get
            {
                return isCurrentRed;
            }
        }
        private static Theme DefauletTheme = new Theme();
        private static Theme GreenTheme = new Theme();
        private static Theme CurrentTheme = new Theme();
        public static Theme cuTheme
        {
            get
            {
                return CurrentTheme;
            }
        }
      
        #region 二级内容标题
        public static DependencyProperty SecondTextBrushProperty = DependencyProperty.Register("SecondTextBrush",
                                                                     typeof(Brush),
                                                                     typeof(Theme),
                                                                     new PropertyMetadata(/*"默认值"*/null, null));

        public Brush SecondTextBrush
        {
            get
            {
                return (Brush)base.GetValue(SecondTextBrushProperty);
            }
            set
            {
                base.SetValue(SecondTextBrushProperty, value);
            }
        }


        public static DependencyProperty TextBlueAndBlackBrushProperty = DependencyProperty.Register("BlueAndBlack",
                                                                     typeof(Brush),
                                                                     typeof(Theme),
                                                                     new PropertyMetadata(/*"默认值"*/null, null));
        public Brush BlueAndBlack
        {
            get
            {
                return (Brush)base.GetValue(TextBlueAndBlackBrushProperty);
            }
            set
            {
                base.SetValue(TextBlueAndBlackBrushProperty, value);
            }
        }

        public static DependencyProperty TextGrayAndWhiteBrushProperty = DependencyProperty.Register("GrayAndWhite",
                                                                     typeof(Brush),
                                                                     typeof(Theme),
                                                                     new PropertyMetadata(/*"默认值"*/null, null));
        public Brush GrayAndWhite
        {
            get
            {
                return (Brush)base.GetValue(TextGrayAndWhiteBrushProperty);
            }
            set
            {
                base.SetValue(TextGrayAndWhiteBrushProperty, value);
            }
        }


        public static DependencyProperty TextIndexgrayAndWhiteBrushProperty = DependencyProperty.Register("IndexgrayAndWhite",
                                                                    typeof(Brush),
                                                                    typeof(Theme),
                                                                    new PropertyMetadata(/*"默认值"*/null, null));
        public Brush IndexgrayAndWhite
        {
            get
            {
                return (Brush)base.GetValue(TextIndexgrayAndWhiteBrushProperty);
            }
            set
            {
                base.SetValue(TextIndexgrayAndWhiteBrushProperty, value);
            }
        }


        public static DependencyProperty TextGrayAndBlueBrushProperty = DependencyProperty.Register("GrayAndBlue",
                                                                     typeof(Brush),
                                                                     typeof(Theme),
                                                                     new PropertyMetadata(/*"默认值"*/null, null));
        public Brush GrayAndBlue
        {
            get
            {
                return (Brush)base.GetValue(TextGrayAndBlueBrushProperty);
            }
            set
            {
                base.SetValue(TextGrayAndBlueBrushProperty, value);
            }
        }



        public static DependencyProperty TextNavyAndBlueBrushProperty = DependencyProperty.Register("NavyAndBlue",
                                                                     typeof(Brush),
                                                                     typeof(Theme),
                                                                     new PropertyMetadata(/*"默认值"*/null, null));
        public Brush NavyAndBlue
        {
            get
            {
                return (Brush)base.GetValue(TextNavyAndBlueBrushProperty);
            }
            set
            {
                base.SetValue(TextNavyAndBlueBrushProperty, value);
            }
        }




        #endregion


        #region 文本的颜色
        public static DependencyProperty TextBrushProperty = DependencyProperty.Register("TextBrush",
                                                                     typeof(Brush),
                                                                     typeof(Theme),
                                                                     new PropertyMetadata(/*"默认值"*/null, null));

        public Brush TextBrush
        {
            get
            {
                return (Brush)base.GetValue(TextBrushProperty);
            }
            set
            {
                base.SetValue(TextBrushProperty, value);
            }
        }

        #endregion
        #region 所有页面的一级标题
        public static DependencyProperty TitleBrushProperty = DependencyProperty.Register("TitleBrush",
                                                                     typeof(Brush),
                                                                     typeof(Theme),
                                                                     new PropertyMetadata(/*"默认值"*/null, null));

        public Brush TitleBrush
        {
            get
            {
                return (Brush)base.GetValue(TitleBrushProperty);
            }
            set
            {
                base.SetValue(TitleBrushProperty, value);
            }
        }

        #endregion

        #region targetButton的background
        public static DependencyProperty lexunTBBackBrushProperty = DependencyProperty.Register("lexunTBBackBrush",
                                                                     typeof(Brush),
                                                                     typeof(Theme),
                                                                     new PropertyMetadata(/*"默认值"*/null, null));

        public Brush lexunTBBackBrush
        {
            get
            {
                return (Brush)base.GetValue(lexunTBBackBrushProperty);
            }
            set
            {
                base.SetValue(lexunTBBackBrushProperty, value);
            }
        }

        #endregion
        #region applicationbar的background
        public static DependencyProperty ApplicationBarForgetBrushProperty = DependencyProperty.Register("ApplicationBarForgetBrush",
                                                                     typeof(Brush),
                                                                     typeof(Theme),
                                                                     new PropertyMetadata(/*"默认值"*/null, null));

        public Brush ApplicationBarForgetBrush
        {
            get
            {
                return (Brush)base.GetValue(ApplicationBarForgetBrushProperty);
            }
            set
            {
                base.SetValue(ApplicationBarForgetBrushProperty, value);
            }
        }

        #endregion
        #region targetButton的forgetground
        public static DependencyProperty lexunTBForgetBrushProperty = DependencyProperty.Register("lexunTBForgetBrush",
                                                                     typeof(Brush),
                                                                     typeof(Theme),
                                                                     new PropertyMetadata(/*"默认值"*/null, null));

        public Brush lexunTBForgetBrush
        {
            get
            {
                return (Brush)base.GetValue(lexunTBForgetBrushProperty);
            }
            set
            {
                base.SetValue(lexunTBForgetBrushProperty, value);
            }
        }

        #endregion
        #region targetButton的forgetground
        public static DependencyProperty lexunReplyBackBrushProperty = DependencyProperty.Register("lexunReplyBackBrush",
                                                                     typeof(Brush),
                                                                     typeof(Theme),
                                                                     new PropertyMetadata(/*"默认值"*/null, null));

        public Brush lexunReplyBackBrush
        {
            get
            {
                return (Brush)base.GetValue(lexunReplyBackBrushProperty);
            }
            set
            {
                base.SetValue(lexunReplyBackBrushProperty, value);
            }
        }

        #endregion

        //值拷贝
        public void copy(Theme a)
        {
            //  TextBrush = a.TextBrush;
            //  BkImg = a.BkImg;

            MemberInfo[] memInfos = a.GetType().GetMembers(); //获取成员变量
            foreach (MemberInfo mInfo in memInfos)            //遍历成员变量
            {
                if (mInfo is PropertyInfo)
                {
                    PropertyInfo info = mInfo as PropertyInfo;
                    if (info.CanWrite)
                    {

                        info.SetValue(this, info.GetValue(a, null), null);

                    }

                }

            }
        }
    }
}
